/*
 * @Author: 梁 卓
 * @Version: V1.0.0
 * @Date: 2024-09-19 22:39:20
 * @LastEditors: 梁 卓
 * @LastEditTime: 2024-09-29 21:24:04
 * @FilePath: index.js
 * Copyright 2024 Marvin, All Rights Reserved. 
 * 2024-09-19 22:39:20
 * @Description: 
 */
import { createRouter,createWebHistory} from "vue-router";


// 路由信息
const routes = [
    {
        path: "/login",
        name: "login",
        component: () => import("../views/login/index.vue")
    },
    {
        path: "/",
        name: "home",
        component: () => import("../layout/index.vue"),
        children: [
            {
                path: "/list",
                name: "list",
                component: () => import("../views/user/userList.vue"),
                children: [
                    {
                        path: "/chat",
                        name: "chat",
                        component: () => import("../views/chat/index.vue")
                    }
                ]
            },
            {
                path: "/userAdd",
                name: "userAdd",
                component: () => import("../views/user/userAdd.vue"),
                children: [
                    {
                        path: "/add",
                        name: "add",
                        component: () => import("../views/user/add.vue")
                    }
                ]
            }
        ]
    }
];

// 导出路由
const router = createRouter({
    history: createWebHistory(),
    routes,

});

let beforeEach = router.beforeEach((to, from, next) => {
    let token = localStorage.getItem("login-token")
    if (to.name != 'login') {
        if (!token) {
            next({name: 'login'})
        }
    }
    next()
})

export default router;
